#include<stdio.h>
long a[100000];
long i,k,n=5,m=3,weightTotal=32,max=9;
void input(){
    scanf("%ld%ld",&n,&m);
    for(i=0;i<n;i++){
        scanf("%ld",&a[i]);
        weightTotal+=a[i];
        if(max<a[i])max=a[i];
    }
}
int isok(int w){
    long i,j=0,weight=0;
    for(i=0;i<n;i++){
        if(weight+a[i]>w){
            weight=a[i];
            j++;
            if(j>m)return 0;
        }else weight+=a[i];
    }
    if(j<m) return 1;
    else return 0;
}
long find(){
    long smaller=max,bigger=weightTotal,tg;
    while(smaller<=bigger-2){
        tg=(smaller+bigger)/2;
        if(isok(tg))bigger=tg;
        else smaller=tg;
    }
    if(isok(smaller))return smaller;
    return bigger;
}
int main(){
    input();
    printf("%ld",find());
    return 0;
}
